package net.shopxx.action.admin;

import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
import com.opensymphony.xwork2.validator.annotations.Validations;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.annotation.Resource;
import net.shopxx.OOOO0O0O.IIIIIIll;
import net.shopxx.OOOO0OO0.IIlIllII;
import net.shopxx.OOOOOOOO.IIIlIlIl;
import net.shopxx.entity.IIIlIlll;
import net.shopxx.entity.Specification;
import net.shopxx.service.SpecificationService;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.BeanUtils;

@ParentPackage("admin")
public class SpecificationAction extends BaseAdminAction
{
  private static final long serialVersionUID = -3155241538605530207L;
  private Specification specification;
  private List<Specification> specificationValueList;
  private List<File> lIIllIIl = new ArrayList();

  @Resource(name="specificationServiceImpl")
  private SpecificationService specificationService;

  public String add()
  {
    return "input";
  }

  public String edit()
  {
    this.specification = ((Specification)this.specificationService.load(this.id));
    return "input";
  }

  public String list()
  {
	pager = specificationService.findByPager(pager);
	return LIST;
  }

  public String delete()
  {
    for (String str : this.specification)
    {
      Specification localSpecification = (Specification)specificationService.load(str);
      Set localSet = localSpecification.getGoodsSet();
      if ((localSet != null) && (localSet.size() > 0))
        return IIIIIIII(IIIIIIIl.IIIlllIl, "规格[" + localSpecification.getName() + "]已被引用,删除失败!");
    }
    this.specificationService.delete(this.IIIllIII);
    return IIIIIIII(IIIIIIIl.IIIllllI, "删除成功!");
  }

  @Validations(requiredStrings={@com.opensymphony.xwork2.validator.annotations.RequiredStringValidator(fieldName="specification.name", message="规格名称不允许为空!")}, requiredFields={@com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator(fieldName="specification.specificationType", message="规格类型不允许为空!"), @com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator(fieldName="specificationValueList", message="规格值不允许为空!")})
  @InputConfig(resultName="error")
  public String save()
  {
    if (this.specificationValueList.size() == 0)
    {
      addActionError("请至少添加一个商品规格值!");
      return "error";
    }
    IIIlIlIl localIIIlIlIl;
    for (int i = 0; i < this.specificationValueList.size(); i++)
    {
      localIIIlIlIl = (IIIlIlIl)this.specificationValueList.get(i);
      if (localIIIlIlIl != null)
      {
        if (StringUtils.isEmpty(localIIIlIlIl.getName()))
        {
          addActionError("商品规格值名称不允许为空!");
          return "error";
        }
        if ((this.lIIllIIl != null) && (i < this.lIIllIIl.size()) && (this.specification.getSpecificationType() == IIIlIlll.llllIllIl))
        {
          File localFile = (File)this.lIIllIIl.get(i);
          String str = IIIIIIll.IIIIIIII(getServletContext(), localFile);
          localIIIlIlIl.setImagePath(str);
        }
        if (this.specification.getSpecificationType() == IIIlIlll.llllIllII)
          localIIIlIlIl.setImagePath(null);
      }
    }
    Iterator localIterator = this.specificationValueList.iterator();
    while (localIterator.hasNext())
    {
      localIIIlIlIl = (IIIlIlIl)localIterator.next();
      if (localIIIlIlIl == null)
        localIterator.remove();
    }
    this.specification.setSpecificationValueList(this.specificationValueList);
    this.IlIIllll.save(this.specification);
    this.IIIllIll = "specification!list.action";
    return "success";
  }

  @Validations(requiredStrings={@com.opensymphony.xwork2.validator.annotations.RequiredStringValidator(fieldName="specification.name", message="规格名称不允许为空!")}, requiredFields={@com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator(fieldName="specification.specificationType", message="规格类型不允许为空!"), @com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator(fieldName="specificationValueList", message="规格值不允许为空!")})
  @InputConfig(resultName="error")
  public String update()
  {
    if (this.specificationValueList.size() == 0)
    {
      addActionError("请至少添加一个商品规格值!");
      return "error";
    }
    IIIlIlIl localIIIlIlIl;
    for (int i = 0; i < this.specificationValueList.size(); i++)
    {
      localIIIlIlIl = (IIIlIlIl)this.specificationValueList.get(i);
      if (localIIIlIlIl != null)
      {
        if (StringUtils.isEmpty(localIIIlIlIl.getName()))
        {
          addActionError("商品规格值名称不允许为空!");
          return "error";
        }
        if ((this.lIIllIIl != null) && (i < this.lIIllIIl.size()) && (this.specification.getSpecificationType() == IIIlIlll.llllIllIl))
        {
          File localFile = (File)this.lIIllIIl.get(i);
          String str = IIIIIIll.IIIIIIII(getServletContext(), localFile);
          localIIIlIlIl.setImagePath(str);
        }
        if (this.specification.getSpecificationType() == IIIlIlll.llllIllII)
          localIIIlIlIl.setImagePath(null);
      }
    }
    Object localObject = this.specificationValueList.iterator();
    while (((Iterator)localObject).hasNext())
    {
      localIIIlIlIl = (IIIlIlIl)((Iterator)localObject).next();
      if (localIIIlIlIl == null)
        ((Iterator)localObject).remove();
    }
    localObject = (Specification)this.IlIIllll.load(this.id);
    this.specification.setSpecificationValueList(this.specificationValueList);
    BeanUtils.copyProperties(this.specification, localObject, new String[] { "id", "createDate", "modifyDate", "goodsSet" });
    this.IlIIllll.update(localObject);
    this.IIIllIll = "specification!list.action";
    return "success";
  }

  public List<IIIlIlll> getSpecificationTypeList()
  {
    return Arrays.asList(IIIlIlll.values());
  }

  public Specification getSpecification()
  {
    return this.specification;
  }

  public void setSpecification(Specification paramSpecification)
  {
    this.specification = paramSpecification;
  }

  public List<IIIlIlIl> getSpecificationValueList()
  {
    return this.specificationValueList;
  }

  public void setSpecificationValueList(List<IIIlIlIl> paramList)
  {
    this.specificationValueList = paramList;
  }

  public List<File> getSpecificationValueImageList()
  {
    return this.lIIllIIl;
  }

  public void setSpecificationValueImageList(List<File> paramList)
  {
    this.lIIllIIl = paramList;
  }
}

/* Location:           D:\apache-tomcat-7.0.35\webapps\ROOT1\WEB-INF\classes\
 * Qualified Name:     net.shopxx.action.admin.SpecificationAction
 * JD-Core Version:    0.6.2
 */